<template>
    <!-- 添加我的获奖情况弹框-->
<el-dialog
  :visible.sync="visible" class="awards_dialog"
  title="新建获奖情况"
  @close="cancel"
  :close-on-click-modal="false" 
  :close-on-press-escape="false"
  :append-to-body="true">
    <el-form :model="awardsForm" label-width="125px">
        <el-form-item label="竞赛名称：">
            <el-input clearable v-model="awardsForm.contestName"></el-input>
        </el-form-item>
        <el-form-item label="奖项类型：">
          <el-select clearable v-model="awardsForm.categoryId" placeholder="选择奖项分类">
            <el-option v-for="item in typesList"
            :key="item.id" :label="item.categoryName" :value="item.id"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="获奖时间：">
            <!-- <el-input v-model="partyForm.createTime"></el-input> -->
            <div class="block">
                <el-date-picker clearable value-format="yyyy-MM-dd HH:mm:ss"
                    v-model="awardsForm.acquisitionTime"
                    type="datetime"
                    placeholder="选择时间">
                </el-date-picker>
            </div>
        </el-form-item>
        <el-form-item label="奖项等级：">
            <el-input clearable v-model="awardsForm.grade" placeholder="例：一等奖、二等奖、三等奖"></el-input>
        </el-form-item>
        <el-form-item label="奖项级别：">
            <el-input clearable v-model="awardsForm.level" placeholder="例：省级、国级、世界级"></el-input>
        </el-form-item>
    </el-form>
    <div class="awards_button">
        <el-button type="primary" @click="sure">确认</el-button>
        <el-button @click="cancel">取消</el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
    data(){
    return{
        // awardsForm:[],
        visible:false,
        awardsForm:{
          contestName: "",//比赛全称
          level: "",//奖项级别
          grade: "",//奖项等级
          acquisitionTime: "",//获取时间
        },
        typesList:[
          // {
          //   id:"7e1b762a7b5c4b11a6f99cf66c6ed49f",
          //   categoryName:"思想道德"
          // },{
          //   id:"9f31388f829e493c9d10e367c14b0b48",
          //   categoryName:"社会实践"
          // },{
          //   id:"82294844f9944cd8b8ac60b7a12a030d",
          //   categoryName:"学业成绩"
          // },
        ],//奖项分类
      }
    }
  ,
  
  methods:{
    // 进入弹框
    init () {
      this.visible = true
      this.$nextTick(() => {
      })
      this.axios({//查询奖项分类
        headers:{'Authentication':localStorage.getItem('token')},
        method:"get",
        url:"/award/getTreeAwardCategory",
      }).then(res=>{
        if(res.data.code != 20001){
          return this.$message.error(res.data.msg)
        }
        this.typesList = res.data.data
        // console.log(this.typesList)
      })
    },
    Organization(){//获取用户列表
      this.axios({
        headers:{'Authentication':localStorage.getItem('token')},
        method:"get",
        // url:"api/organization/getOrganizationList",
        url:"/organization/getOrganizationList",
      }).then(res=>{
        // console.log(res)
        if(res.data.code != 20001){
          return this.$message.error(res.data.msg)
        }
        else{
          this.OrganizationList = res.data.data.list
          this.Authentication = res.data.data
        }
      })
    },
   
    sure(){//点击确认按钮
      // console.log(this.awardsForm)
        this.axios({
          headers:{'Authentication':localStorage.getItem('token')},
          method:"post",
          // url:"api/award/save",
          url:"/award/save",
          data:this.awardsForm
        }).then(res=>{
          // console.log(res)
          if(res.data.code != 20001){
            return this.$message.error(res.data.msg)
          }
          this.$alert('添加成功', {
            confirmButtonText: '确定',
            callback: action => {
              this.visible = false
              this.awardsForm = {}//清空输入框中保留的内容
              this.$emit('Organization')
            }
          });
      })
    },
    cancel(){
      this.visible = false
      this.awardsForm = {}//清空输入框中保留的内容
    }
  }
}
</script>

<style lang="scss">
  .awards_dialog{
    .el-dialog{
      height: 78vh;
    }
    .awards_button{
      position: absolute;
      bottom: 5vh;
      left: 0;
      width: 100%;
      text-align: center;
    }
  }
</style>